/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>Project: sboot2021 - DbMapper
 * <p>Powered by webrx On 2021-07-29 12:54:47
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
@Repository
public interface DbMapper {
    public List<String> tbs();

    @Select("select count(*) from ${tn}")
    public int count(String tn);

    public List<String> tbs(String db);

    //@Select("show databases")
    public List<String> dbs();

    @Select("select version()")
    public String version();

    @Select("select user,host,authentication_string,plugin from mysql.user")
    public List<Map<String, Object>> userInfo();

    @Select("select database(),user(),version(),@@datadir,@@basedir,@@port")
    public Map<String, Object> dbInfo();

    @Select("show create table ${tb}")
    public Map<String, Object> showCreateTable(String tb);

    @Select("select ${ff} from ${tn} ${ww}")
    public List<Map<String,Object>> list(@Param("tn") String tn,@Param("ff") String field,@Param("ww") String where);


    @Delete("drop table if exists ${tn}")
    public void delTable(String tn);

    @Update("${sql}")
    public void createTable(String sql);
}
